<template>
	<view class="">
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="current" :values="items" v-on:clickItem="onClickItem" :styleType="styleType"
			 :activeColor="activeColor"></uni-segmented-control>
		</view>
		<view style="height:20px;"></view>
		<view class="uni-list">
			<view class="uni-list-cell" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<view class="dotView"></view>
					<!-- <image class="imageView" src="item.image" mode="scaleToFill"></image> -->
					<view class="contentView">
						<text>{{item.type}}</text>
						<text>{{item.title}}</text>
					</view>
					<view class="timeView">{{item.createTime}}</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
	export default {
		components: {
			uniSegmentedControl
		},
		data() {
			return {
				list: [],

				items: [
					'未读消息',
					'已读消息'
				],
				current: 0,
				activeColor: '#007aff',
				styleType: 'button',

				reload: false,

				pageNo: 1,
				viewStatus: 0,
			};
		},
		onLoad() {
			this.getList();
		},
		onPullDownRefresh() {
			this.reload = true;
			this.pageNo = 1;
			this.list = new Array();
			this.getList();
		},
		onReachBottom() {
			this.pageNo++;
			this.getList();
		},
		onShow() {
			if (undefined === getApp().globalData.isRead) {
				getApp().globalData.isRead = 0;
			} else {
				if (getApp().globalData.isRead === 1 && this.current === 0) {
					getApp().globalData.isRead = 0;
					this.reload = true;
					this.pageNo = 1;
					this.list = new Array();
					this.getList();
				}
			}
		},
		methods: {
			onClickItem(index) {
				if (this.current !== index) {
					this.current = index;
					this.viewStatus = index;
					this.pageNo = 1;
					this.list = new Array();
					this.getList();
				}
			},
			getList() {
				this.reload = false;
				uni.stopPullDownRefresh();

				this.$http.get('ac/xagrid/appNoticeService/getNoticeList', {
					pageNo: this.pageNo,
					pageSize: 10,
					viewStatus: this.viewStatus
				}).then((res) => {
					if (res.data.results.length > 0) {
						this.list = this.list.concat(res.data.results);
					}
				});
				console.log("加载更多");
			},
			goDetail(e) {
				uni.navigateTo({
					url: '/pages/news/list2detail-detail/list2detail-detail?id=' + e.id,
				});
			}
		}
	}
</script>

<style>
	.uni-list-cell-navigate {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.dotView {
		width: 10upx;
		height: 10upx;
		border-radius: 5upx;
		background-color: #0FAEFF;
	}

	.imageView {
		width: 100upx;
		height: 100upx;
		background-color: #00B26A;
		margin-left: 20upx;
	}

	.contentView {
		display: flex;
		flex-direction: column;
		align-items: margin-left;
		margin-left: 20upx;
	}

	.timeView {
		margin: auto;
		margin-right: 20upx;
	}
</style>
